package com.work.game.service;

import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.IBinder;

import androidx.annotation.Nullable;

import com.android.volley.Request;
import com.android.volley.VolleyError;
import com.work.game.config.UrlConfig;
import com.work.game.home.ui.model.vo.BaseVo;
import com.work.game.utils.risk.DeviceUtils;
import com.work.game.utils.risk.VirtualApkCheckUtil;
import com.work.game.utils.risk.VirtualCheckCallback;
import com.work.game.volley.httpUtil.HCUParame;
import com.work.game.volley.httpUtil.HUCRequest;
import com.work.game.volley.httpUtil.interfase.HUCCallBackInterfase;
import com.work.game.volley.state.HUCState;

import cn.hutool.core.util.StrUtil;

public class RiskService extends Service implements VirtualCheckCallback, HUCCallBackInterfase {
    //声明SharedPreferences，用来读取xml;
    private SharedPreferences sp;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        VirtualApkCheckUtil.getSingleInstance().checkByPortListening(DeviceUtils.getInstance().getPackageName(this), getSharedPreferences("id"), this);
        return START_STICKY;
    }
    public String getSharedPreferences(String key) {
        sp = getSharedPreferences("setting", MODE_PRIVATE);
        String value = sp.getString(key, "");
        return value;
    }

    @Override
    public void findSuspect(String value) {
        if (StrUtil.isEmpty(value)) {
            return;
        }
        String[] stars = value.split(",");
        BaseVo baseVo = new BaseVo();
        baseVo.setInfo(stars[1]);
        baseVo.setToken(getSharedPreferences("deviceId"));
        HUCRequest.getInstance().executeStr(this, null,
                HUCState.HUC_REQEUST_CODE_2, Request.Method.POST, UrlConfig.URL_SEPARATION,
                HCUParame.getInstance().getRequestParameter(baseVo), true);
    }

    @Override
    public void onSuccessfulStrType(int inputType, Object response) {

    }

    @Override
    public void onFailStrType(int inputType, Object response) {

    }

    @Override
    public void onSuccessfulBitampType(int inputType, Bitmap response) {

    }

    @Override
    public void onErrorResponse(int inputType, VolleyError response) {

    }

    @Override
    public void onErrorLogin(int inputType, Object response) {

    }

    @Override
    public void onResetLogin(Object response) {

    }
}

